﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace HumanResources
{
    public class Company : TaxEntity
    {
        private LinkedList<Payable> employees;

        public Company(String name, String taxid)
            : base (name, taxid)
        {
            employees = new LinkedList<Payable>();
        }

        protected override string TaxIdRegularExpression
        {
            get
            {
                return @"^\d\d-\d{7}$";
            }
        }

        public void Hire(Payable newHire)
        {
            if (newHire != null)
            {
                employees.AddLast(newHire);
            }
            else
                throw new ValidationException("Cannot hire null ");
        }

        public IEnumerable<Payable> Employees
        {
            get { return employees; }
        }

        public IEnumerable<Payable> AllEmployeesByName
        {
            get { var q = from p in employees orderby p.Name select p; 
                return q;}
        }
  
        public override float Pay()
        {
            float total = 0;

            var q = from payable in employees where payable.Name.CompareTo("M")>0 orderby Name select payable;
            foreach (Payable p in q)
            {

            }
            foreach (Payable e in employees.Where(p => p.Name.Length > 3))
            {
                if (e != null)
                    total += e.Pay();
            }
            return total;
        }

    }
}
